
import { _decorator, Component, Node, instantiate, randomRange, v3, tween, Label, math, log, RigidBody, BoxCollider, Light, color } from 'cc';
import { App } from '../../Script/App';
import { SceneBase } from '../../Script/SceneBase';
import { Toast } from '../Public/Script/Toast';
const { ccclass, property } = _decorator;

@ccclass('Tarot')
export class Tarot extends SceneBase {
    @property(Node)
    nodeItem!: Node;

    @property(Label)
    label!: Label

    @property(Light)
    light!: Light

    async onBtnBack() {
        // await Toast.show('0123456789')
        App.changeScene('Test', 'Test')
    }

    async start() {
        super.start()

        this.nodeItem.active = false

        const r = 8
        const total = 60
        const degOffset = 360 / total
        for (let i = 0; i < total; i++) {
            const node = instantiate(this.nodeItem)
            node.active = true
            node.parent = this.nodeItem.parent
            node.position = v3(Math.sin(math.toRadian(i * degOffset)) * r, node.scale.y / 2, Math.cos(math.toRadian(i * degOffset)) * r)
            node.eulerAngles = v3(0, i * degOffset, 0)

            this.label.string = `${i + 1}`

            await App.asyncTween(this.node, tween().delay(0.1))

            if (i != 59) {
                continue
            }
            const body = node.getComponent(RigidBody)
            body?.applyLocalForce(v3(body.mass * 30, 0, 0), v3(0, node.scale.y, 0))
        }
    }
}
